Get Gaia data

Good Demos:

Epic ID Description
202136094 Campaign 0 large pixel mask, used in tweeted GIF animation teaser: RA, DEC— 98.6569500, 16.8438700
246909194 Campaign 13, 100 pixel mask
In [1]:
import numpy as np
from astroquery.vizier import Vizier
from astropy.coordinates import Angle
from lightkurve import KeplerTargetPixelFile
In [2]:
tpf = KeplerTargetPixelFile.from_archive(247604290)
INFO: Found cached file ./mastDownload/K2/ktwo247604290-c13_lc/ktwo247604290-c13_lpd-targ.fits.gz with expected size 19697648. [astroquery.query]

Get the campaign 13 FFI also.

In [3]:
from astropy.io import fits
In [4]:
ffi_raw = fits.open('/Volumes/Truro/ffi/ktwo2017079075530-c13_ffi-cal.fits')
In [5]:
ffi_8_3 = ffi_raw['MOD.OUT 8.3']
In [6]:
tpf.interact()
Loading BokehJS ...
In [7]:
from astropy.coordinates import SkyCoord
In [8]:
c1 = SkyCoord(tpf.ra, tpf.dec, frame='icrs', unit='deg')
In [36]:
Vizier.ROW_LIMIT = 10000
In [43]:
result = Vizier.query_region(c1, catalog=["I/345/gaia2"], radius=Angle(1200, "arcsec"))["I/345/gaia2"]
In [44]:
radecs = np.vstack([result['RA_ICRS'].data.data, result['DE_ICRS'].data.data]).T
In [45]:
radecs.shape
Out[45]:
(7448, 2)
In [46]:
from astropy.wcs import WCS
In [47]:
wcs_8_3 = WCS(header=ffi_8_3.header)
In [48]:
wcs_8_3
Out[48]:
WCS Keywords

Number of WCS axes: 2
CTYPE : 'RA---TAN-SIP'  'DEC--TAN-SIP'
CRVAL : 76.09268505969324  22.55459653238129
CRPIX : 533.0  521.0
CD1_1 CD1_2  : 0.0003593093170276045  -0.001044485756926
CD2_1 CD2_2  : -0.001044333134869  -0.0003585363888737
NAXIS : 1132  1070
In [54]:
coords = wcs_8_3.all_world2pix(radecs, 1)
In [55]:
zp = (tpf.pos_corr1 == 0) & (tpf.pos_corr2 == 0)
zp_loc = np.where(zp)
zp_loc
Out[55]:
(array([1872]),)
In [56]:
nx, ny = ffi_8_3.data.shape
In [57]:
# %load -r 611:795 ../../../lightkurve/targetpixelfile.py
def show_gaia(self):
    """Display an interactive Target Pixel File with positions of Gaia DR2 sources."""
    try:
        from ipywidgets import interact
        import ipywidgets as widgets
        from bokeh.io import push_notebook, show, output_notebook
        from bokeh.plotting import figure, ColumnDataSource
        from bokeh.models import Span, Range1d, LinearAxis, LogColorMapper
        from bokeh.layouts import row
        from bokeh.models.tools import HoverTool
        from IPython.display import display
        output_notebook()
    except ImportError:
        raise ImportError('The quicklook tool requires Bokeh and ipywidgets. '
                          'See the .interact() tutorial')

    # Each data source will later become a hover-over tooltip
    #source = ColumnDataSource(data=dict(
    #                          flux=lc.flux,
    #                          quality_code=lc.quality,
    #                          quality=np.array(qual_strings)))


    # Figure 2 shows the Target Pixel File stamp with log screen stretch
    fig2 = figure(plot_width=600, plot_height=600,
                  tools="pan,wheel_zoom,box_zoom,save,reset",
                  title='K2 Source EPIC 202136094 Campaign 0 pixel data (CCD {}.{})'.format(
                            self.module, self.output))
    fig2.yaxis.axis_label = 'Pixel Row Number'
    fig2.xaxis.axis_label = 'Pixel Column Number'

    pedestal = np.nanmin(ffi_8_3.data)
    stretch_dims = np.prod(ffi_8_3.data.shape)
    screen_stretch = ffi_8_3.data.reshape(stretch_dims) - pedestal
    screen_stretch = screen_stretch[np.isfinite(screen_stretch)]  # ignore NaNs
    screen_stretch = screen_stretch[screen_stretch > 0.0]
    vlo = np.min(screen_stretch)
    vhi = np.max(screen_stretch)
    vstep = (np.log10(vhi) - np.log10(vlo)) / 300.0  # assumes counts >> 1.0!
    lo, med, hi = np.nanpercentile(screen_stretch, [1, 50, 95])
    color_mapper = LogColorMapper(palette="Viridis256", low=lo, high=hi)

    #fig2_dat = fig2.image([self.flux[1872, :, :] - pedestal], x=self.column,
    #                      y=self.row, dw=self.shape[2], dh=self.shape[1],
    #                      dilate=False, color_mapper=color_mapper)

    fig2_dat = fig2.image([ffi_8_3.data - pedestal], x=0,
                      y=0, dw=ny, dh=nx,
                      dilate=False, color_mapper=color_mapper)



    source = ColumnDataSource(data=dict(ra=result['RA_ICRS'].data.data,
                                        dec=result['DE_ICRS'].data.data,
                                        source=result['Source'].data.data,
                                        Gmag=result['Gmag'].data.data,
                                        plx=result['Plx'].data.data,
                                        x=coords[:, 0],#+tpf.column,
                                        y=coords[:, 1]))#+tpf.row))


    r = fig2.circle('x', 'y', source=source,fill_alpha=0.3, size=8,
                line_color=None, selection_color="firebrick",
                nonselection_fill_alpha=0.0, nonselection_line_color=None,
                nonselection_line_alpha=0.0, fill_color="firebrick",
                hover_fill_color="firebrick", hover_alpha=0.9,
                hover_line_color="white")

    fig2.add_tools(HoverTool(tooltips=[("Source", "@source"),("G", "@Gmag"),("Parallax", "@plx"),
                                    ("RA", "@ra{0,0.00000000}"),
                                     ("DEC", "@dec{0,0.00000000}"),
                                      ("x", "@x"),
                                     ("y", "@y")],
                                     renderers=[r],
                                     mode='mouse',
                                     point_policy="snap_to_data"))

    # The figures appear before the interactive widget sliders
    show(fig2, notebook_handle=True)

Here we go!

In [58]:
show_gaia(tpf)
Loading BokehJS ...
In [ ]:

In [ ]:

In [ ]:

In [ ]:

In [ ]:

In [ ]:

In [ ]:

Find a huge TPF— many npix, (but not too many)

In [14]:
import pandas as pd
In [15]:
df = pd.read_csv('../../../../k2-target-index/k2-target-pixel-files.csv.gz')
In [16]:
df.columns
Out[16]:
Index(['filename', 'url', 'filesize', 'object', 'keplerid', 'obsmode',
       'campaign', 'data_rel', 'channel', 'module', 'output', 'ra_obj',
       'dec_obj', 'kepmag', 'cadences', 'lc_start', 'lc_end', 'gain',
       'readnois', 'meanblck', 'cdpp3_0', 'cdpp6_0', 'cdpp12_0', 'npix',
       'naxis1', 'naxis2', 'crpix1', 'crpix2', 'crval1', 'crval2', 'cdelt1',
       'cdelt2', 'pc1_1', 'pc1_2', 'pc2_1', 'pc2_2', 'crval1p', 'crval2p',
       'corners', 'ra_min', 'ra_max', 'dec_min', 'dec_max'],
      dtype='object')
In [72]:
df_sub = df[['keplerid','npix', 'campaign', 'kepmag', 'ra_obj', 'dec_obj']].sort_values('npix', ascending=False)
In [73]:
df_sub.npix.describe()
Out[73]:
count    464754.000000
mean        107.601193
std         251.775228
min           1.000000
25%          15.000000
50%          72.000000
75%         115.000000
max       16148.000000
Name: npix, dtype: float64
In [74]:
# %load /Users/obsidian/Desktop/defaults.py
import matplotlib.pyplot as plt
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
In [ ]:

In [75]:
np.log10(16000)
Out[75]:
4.204119982655925
In [76]:
bins = np.logspace(0, 4.5, 20)
bins
Out[76]:
array([1.00000000e+00, 1.72521055e+00, 2.97635144e+00, 5.13483291e+00,
       8.85866790e+00, 1.52830673e+01, 2.63665090e+01, 4.54877795e+01,
       7.84759970e+01, 1.35387618e+02, 2.33572147e+02, 4.02961132e+02,
       6.95192796e+02, 1.19935395e+03, 2.06913808e+03, 3.56969885e+03,
       6.15848211e+03, 1.06246783e+04, 1.83298071e+04, 3.16227766e+04])
In [77]:
plt.hist(df_sub.npix[df_sub.npix.notnull()].values, bins=bins);
plt.yscale('log')
plt.xscale('log')
../../../_images/tutorials_under_development_.ipynb_checkpoints_ffi-get_gaia-checkpoint_41_0.png
In [78]:
df.columns
Out[78]:
Index(['filename', 'url', 'filesize', 'object', 'keplerid', 'obsmode',
       'campaign', 'data_rel', 'channel', 'module', 'output', 'ra_obj',
       'dec_obj', 'kepmag', 'cadences', 'lc_start', 'lc_end', 'gain',
       'readnois', 'meanblck', 'cdpp3_0', 'cdpp6_0', 'cdpp12_0', 'npix',
       'naxis1', 'naxis2', 'crpix1', 'crpix2', 'crval1', 'crval2', 'cdelt1',
       'cdelt2', 'pc1_1', 'pc1_2', 'pc2_1', 'pc2_2', 'crval1p', 'crval2p',
       'corners', 'ra_min', 'ra_max', 'dec_min', 'dec_max'],
      dtype='object')
In [79]:
98.49476
Out[79]:
98.49476
In [80]:
df_sub[(df_sub.npix >300) & (df_sub.npix <350) & (df_sub.campaign==13)]
Out[80]:
keplerid npix campaign kepmag ra_obj dec_obj
227041 210974656 324 13 17.589 66.094905 22.578190
225774 210922747 324 13 18.458 66.074415 21.749506
224932 210880132 324 13 18.036 66.352680 21.082788
224876 210877078 324 13 18.355 65.579040 21.035210
224824 210874750 324 13 17.826 65.898975 20.999929
413411 246734660 324 13 18.148 67.966950 14.998843
430400 247895464 324 13 9.025 66.891885 25.061587
220323 210681875 324 13 18.150 67.834110 18.107376
431044 248018164 324 13 16.397 70.411770 25.940765
220349 210682652 324 13 18.128 67.848930 18.118714
412825 246672335 324 13 9.060 72.690015 14.217909
220502 210689083 324 13 17.319 67.906140 18.206800
219444 210640612 324 13 18.248 67.148490 17.539869
419827 247178524 324 13 18.334 70.764765 19.418951
421199 247263316 324 13 9.158 79.859025 20.218383
415678 246873969 324 13 14.815 77.689740 16.499481
418758 247096671 324 13 9.230 78.955410 18.638190
416743 246914709 324 13 18.392 72.368280 16.895397
417942 247000196 324 13 18.455 74.909640 17.725349
416241 246893563 324 13 18.252 68.953530 16.691408
418211 247027353 324 13 16.373 68.366235 17.978790
418368 247044744 324 13 17.293 74.966130 18.144341
415692 246874445 324 13 17.255 69.215235 16.503750
421685 247285516 324 13 17.328 71.966460 20.421499
414614 246820783 324 13 9.108 68.357295 15.960932
427169 247590222 324 13 16.077 68.318760 22.889000
427297 247599464 324 13 18.346 71.579685 22.960396
427350 247604290 324 13 15.181 75.742650 22.997731
423133 247371727 324 13 18.412 79.537905 21.167265
220758 210699670 324 13 17.427 67.998675 18.358473
426972 247576278 324 13 17.074 68.334630 22.782583
421012 247253979 318 13 9.456 79.810170 20.132274
222105 210750447 318 13 9.361 66.752505 19.115766
427939 247662958 306 13 8.508 75.283395 23.439021
428742 247717508 306 13 8.618 74.716815 23.836686
425758 247509556 306 13 8.707 74.963730 22.268545
428935 247732272 306 13 8.545 73.656720 23.937837
429063 247742004 306 13 8.802 74.030475 24.004566
427938 247662958 306 13 8.508 75.283395 23.439021
428532 247705520 306 13 8.870 74.886540 23.751925
427849 247651802 306 13 8.737 72.966795 23.354669
420638 247236218 306 13 8.414 73.722705 19.967631
429064 247742016 306 13 8.793 74.029725 24.004624
In [38]:
junk = df_sub.iloc[9902]
In [ ]:
# %load -r 611:795 ../../../lightkurve/targetpixelfile.py